package fmi.chesstern.pieces.strategy;

import java.util.HashSet;
import java.util.Set;


import fmi.chesstern.game.BoardField;
import fmi.chesstern.game.GameBoardState;
import fmi.chesstern.pieces.ChessPieceColor;

public class KnightStrategy implements ChessPieceStrategy {
	private static final int[][] offsets = {
		{-2, 1},
		{-1, 2},
		{2, 1},
		{1, 2},
		{2, -1},
		{1, -2},
		{-2, -1},
		{-1, -2},
	};
	
	public Set<BoardField> getValidNewPositions(GameBoardState board, BoardField currentPosition) {
		Set<BoardField> result = new HashSet<BoardField>();
		
		ChessPieceColor color = board.getPieceAt(currentPosition).getColor();
		
		for (int[] offset : offsets) {
			BoardField newPosition = currentPosition.offsetBy(offset[0], offset[1]);
			
			if (StrategyUtilities.canPositionOn(board, newPosition, color)) {
				result.add(newPosition);
			}
		}
		
		return result;
	}
}
